using QFramework;
using UnityEngine;

namespace ProjectSurvivor
{
	/// <summary>
	/// 溶解
	/// </summary>
    public class Dissolve:MonoBehaviour
		{
			public Material Material;
			//获取shader属性ID，用于设置溶解颜色和溶解程度
			private static readonly int Color=Shader.PropertyToID("_Color");
			private static readonly int Fade=Shader.PropertyToID("_Fade");
			public Color DissolveColor;
			private void Start()
			{
				var matical=Instantiate(Material);
				GetComponent<SpriteRenderer>().material=matical;
				//设置溶解颜色
				matical.SetColor(Color,DissolveColor);
				// 创建溶解和缩放动画  从完全不溶解(fade = 1)到完全溶解(fade = 0)
				ActionKit.Lerp(1,0,0.5f,(fade)=>//淡入淡出效果中的透明度值0-1
				{
					//// 设置溶解程度
					matical.SetFloat(Fade,fade);
					//// 设置缩放 稍稍变大的效果
					this.LocalScale(1+(1-fade)*0.5f);
				}).Start(this,()=>
				{
					Destroy(matical);
					this.DestroyGameObjGracefully();
				});
			}

		}
}
